﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using SolutionFramework.Entities;
using System.Reflection;
using AbstraX.ServerInterfaces;
using System.ServiceModel.DomainServices.Server;
using VisualStudioProvider;
using VisualStudioProvider.Configuration;
using log4net.Config;
using log4net;

namespace SolutionFramework.Web
{
    public class Global : System.Web.HttpApplication
    {
        private static DomainHostApplication domainServiceHostApplication;

        public static DomainHostApplication DomainServiceHostApplication
        {
            get
            {
                if (domainServiceHostApplication == null)
                {
                    domainServiceHostApplication = new DomainHostApplication();
                }

                return domainServiceHostApplication;
            }
        }

        protected void Application_Start(object sender, EventArgs e)
        {
            ContainerConfiguration.Configure();
            VSConfigProvider.Index();

            DomainService.Factory = new DomainServiceFactory(ContainerConfiguration.Container);
        }

        protected void Session_Start(object sender, EventArgs e)
        {
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {
            var factory = (DomainServiceFactory)DomainService.Factory;

            factory.Shutdown();
        }
    }
}